package org.dbrd.model;

import java.util.ArrayList;
import java.util.List;

import org.dbrd.Config;

public class MasterDetectionBugReport extends DetectionBugReport {

	private final List<DuplicateDetectionBugReport> duplicates;

	public MasterDetectionBugReport(int id, String originalSummary, String processedSummary, String originalDescription,
			String processedDescription, int duplicateId, final int priority, final String version, final String subComponent,
			final String issueType, String component) {
		super(id, originalSummary, processedSummary, originalDescription, processedDescription, duplicateId, priority, version,
				subComponent, issueType, component);
		this.duplicates = new ArrayList<DuplicateDetectionBugReport>(0);
	}

	@Override
	public boolean isDuplicated() {
		if (Config.CHECKING) {
			if (super.isDuplicated()) {
				throw new RuntimeException("cannot be duplicated for a master report.");
			}
		}
		return false;
	}

	public List<DuplicateDetectionBugReport> getDuplicates() {
		return duplicates;
	}

	public void addDuplicate(DuplicateDetectionBugReport duplicate) {
		if (Config.CHECKING) {
			if (duplicate.getDuplicateId() != this.id) {
				throw new RuntimeException("duplicate report " + duplicate.getId() + " is not duplicate to this report " + this.getId());
			}
		}
		this.duplicates.add(duplicate);
	}

	public boolean hasDuplicates() {
		return !this.duplicates.isEmpty();
	}
}
